//
//  WorkInfoTableViewCell.m
//  LubanWork
//
//  Created by xiaotong on 2020/1/2.
//  Copyright © 2020 xiaohao. All rights reserved.
//

#import "WorkInfoTableViewCell.h"

@implementation WorkInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = ColorWhite;
        [self.contentView addSubview:self.workNameLab];
        [self.workNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(kSCRATIO(19));
            make.left.equalTo(self.contentView).offset(kSCRATIO(25.5));
            make.height.mas_offset(kSCRATIO(15));
            make.right.equalTo(self.contentView).offset(-kSCRATIO(19));
        }];
        [self.contentView addSubview:self.moneyOfDayLab];
        [self.moneyOfDayLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.workNameLab.mas_bottom).offset(kSCRATIO(12));
            make.left.equalTo(self.contentView).offset(kSCRATIO(25));
//            make.width.mas_offset(kSCRATIO(60));
            make.height.mas_offset(kSCRATIO(13.5));
        }];
        
        [self.contentView addSubview:self.workTypeLab];
        [self.workTypeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.moneyOfDayLab.mas_bottom);
            make.left.equalTo(self.moneyOfDayLab.mas_right).offset(kSCRATIO(20));
            make.height.mas_offset(kSCRATIO(12));
            make.right.equalTo(self.contentView.mas_right).offset(-kSCRATIO(19));
        }];
    }
    return self;
}


-(UILabel *)workNameLab{
    if (!_workNameLab) {
        _workNameLab = [UILabel CreatLabeltext:@"兼职名称" Font:kFONT(15) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
    }
    return _workNameLab;
}

-(UILabel *)moneyOfDayLab{
    if (!_moneyOfDayLab) {
        _moneyOfDayLab = [UILabel CreatLabeltext:@"88元/天" Font:kFONT(12) Textcolor:kColorFromRGBHex(0x775FFB) textAlignment:NSTextAlignmentLeft];
    }
    return _moneyOfDayLab;
}

-(UILabel *)workTypeLab{
    if (!_workTypeLab) {
        _workTypeLab = [UILabel CreatLabeltext:@"日结 | 长期 | 男女不限" Font:kFONT(12) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
    }
    return _workTypeLab;
}


-(void)setMoneyWithString:(NSString *)Money WithType:(WorkStyleType)type{
    if (Money == nil || Money.length == 0) {
        return;
    }
    NSString *typeString ;
    switch (type) {
        case WorkStyleTypeNone:
            typeString = @"天";
            break;
        case WorkStyleTypeDays:
            typeString = @"天";
            break;
        case WorkStyleTypeYear:
            typeString = @"年";
            break;
        case WorkStyleTypeHours:
            typeString = @"小时";
            break;
        case WorkStyleTypeMonths:
            typeString = @"月";
            break;
        default:
            typeString = @"天";
            break;
    }
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元/%@",Money,typeString]];
    NSRange moneyRang = [[string string] rangeOfString:Money];
    
    [string addAttribute:NSFontAttributeName value:kFONT(18) range:moneyRang];
    
    _moneyOfDayLab.attributedText = string;
}

@end
